//
//  XLCycleCell.m
//  XLCycleCollectionViewDemo
//
//  Created by MengXianLiang on 2017/3/6.
//  Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import "XLCycleCell.h"

@interface XLCycleCell () {
     UILabel *titleLabels;
     UILabel *label;
     UILabel *label1;
     UILabel *label2;
     UILabel *label3;
     UILabel *label4;
     UILabel *label5;
     UILabel *label6;
     UILabel *label7;
     UILabel *label8;
     UIView *lineView;
     UIView *lineView1;

}
@end

@implementation XLCycleCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self buildUI];
    }
    return self;
}

- (void)buildUI {
    
    titleLabels = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, self.width - 20, 20)];
    titleLabels.textAlignment = 1;
    titleLabels.textColor = [Networking colorWithHexString:@"#6A8FA6"];
    titleLabels.backgroundColor = kWidgetBackGroundColor;
    titleLabels.font = [UIFont fontWithName:PingFangSCRegular size:15];

    label = [[UILabel alloc]initWithFrame:CGRectMake(0, titleLabels.bottom + 10, self.width / 3, 20)];
    label.textAlignment = 1;
    label.textColor = [Networking colorWithHexString:@"#6A8FA6"];
    label.font = [UIFont fontWithName:PingFangSCRegular size:12];
    label.text = @"产量";
    
    label1 = [[UILabel alloc]initWithFrame:CGRectMake(label.right, titleLabels.bottom + 10, self.width / 3, 20)];
    label1.textAlignment = 1;
    label1.textColor = [Networking colorWithHexString:@"#6A8FA6"];
    label1.font = [UIFont fontWithName:PingFangSCRegular size:12];
    label1.text = @"平均产量";
    
    label2 = [[UILabel alloc]initWithFrame:CGRectMake(label1.right, titleLabels.bottom + 10, self.width / 3, 20)];
    label2.textAlignment = 1;
    label2.textColor = [Networking colorWithHexString:@"#6A8FA6"];
    label2.font = [UIFont fontWithName:PingFangSCRegular size:12];
    label2.text = @"最高产量";
    
    label3 = [[UILabel alloc]initWithFrame:CGRectMake(0, label.bottom + 10, self.width / 3, 20)];
    label3.textAlignment = 1;
    label3.textColor = [Networking colorWithHexString:@"#93B5CF"];
    label3.font = [UIFont fontWithName:PingFangSCMedium size:20];
    
    label4 = [[UILabel alloc]initWithFrame:CGRectMake(label.right,label1.bottom +  10, self.width / 3, 20)];
    label4.textAlignment = 1;
    label4.textColor = [Networking colorWithHexString:@"#93B5CF"];
    label4.font = [UIFont fontWithName:PingFangSCMedium size:20];
    
    label5 = [[UILabel alloc]initWithFrame:CGRectMake(label1.right, label2.bottom + 10, self.width / 3, 20)];
    label5.textAlignment = 1;
    label5.textColor = [Networking colorWithHexString:@"#93B5CF"];
    label5.font = [UIFont fontWithName:PingFangSCMedium size:20];
    
    label6 = [[UILabel alloc]initWithFrame:CGRectMake(0, label3.bottom + 10, self.width / 3, 20)];
    label6.textAlignment = 1;
    label6.textColor = [Networking colorWithHexString:@"#00C3A2"];
    label6.font = [UIFont fontWithName:PingFangSCMedium size:12];
    
    label7 = [[UILabel alloc]initWithFrame:CGRectMake(label.right,label3.bottom +  10, self.width / 3, 20)];
    label7.textAlignment = 1;
    label7.textColor = [Networking colorWithHexString:@"#409EFF"];
    label7.font = [UIFont fontWithName:PingFangSCMedium size:12];
    
    label8 = [[UILabel alloc]initWithFrame:CGRectMake(label1.right, label3.bottom + 10, self.width / 3, 20)];
    label8.textAlignment = 1;
    label8.textColor = [Networking colorWithHexString:@"#7467D0"];
    label8.font = [UIFont fontWithName:PingFangSCMedium size:12];
    
    lineView = [[UIView alloc]initWithFrame:CGRectMake(self.width / 3, label.bottom, 1, 40)];
    lineView.backgroundColor = [Networking colorWithHexString:@"#93B5CF"];

    lineView1 = [[UIView alloc]initWithFrame:CGRectMake(self.width / 3 * 2, label.bottom, 1, 40)];
    lineView1.backgroundColor = [Networking colorWithHexString:@"#93B5CF"];

    [self addSubview:titleLabels];
    [self addSubview:label];
    [self addSubview:label1];
    [self addSubview:label2];
    [self addSubview:label3];
    [self addSubview:label4];
    [self addSubview:label5];
    [self addSubview:label6];
    [self addSubview:label7];
    [self addSubview:label8];
    [self addSubview:lineView];
    [self addSubview:lineView1];
}
- (void)setModel:(HOutputModel *)model {
    _model = model;
    label3.text = [NSString stringWithFormat:@"%.2f",[model.total floatValue]];
    label4.text = [NSString stringWithFormat:@"%.2f",[model.average floatValue]];
    label5.text = [NSString stringWithFormat:@"%.2f",[model.highest floatValue]];
    if (model.total_change.length == 0) {
        model.total_change = @"0";
    }else if (model.average_change.length == 0 ) {
        model.average_change = @"0";
    }else if (model.highest_change.length == 0) {
        model.highest_change = @"0";
    }
    
    NSString *total_change;
    if ([model.total_change floatValue] > 0) {
        total_change = [NSString stringWithFormat:@"↑%@",model.total_change?:@"0"];
    }else if ([model.total_change floatValue] == 0) {
        total_change = [NSString stringWithFormat:@"-"];
    }else {
        total_change = [NSString stringWithFormat:@"↓%@",model.total_change?:@"0"];
    }
    label6.text = total_change;
    NSString *average_change;
    if ([model.average_change floatValue] > 0) {
        average_change = [NSString stringWithFormat:@"↑%@",model.average_change?:@"0"];
    }else if ([model.average_change floatValue] == 0) {
        average_change =  [NSString stringWithFormat:@"-"];
    }else {
        average_change = [NSString stringWithFormat:@"↓%@",model.average_change?:@"0"];
    }
    label7.text = average_change;
    
    NSString *highest_change;
    if ([model.highest_change floatValue] > 0) {
        highest_change = [NSString stringWithFormat:@"↑%@",model.highest_change?:@"0"];
    }else if ([model.highest_change floatValue] == 0) {
        highest_change =  [NSString stringWithFormat:@"-"];
    }else {
        highest_change = [NSString stringWithFormat:@"↓%@",model.highest_change?:@"0"];
    }
    label8.text = highest_change;
    
    if ([model.title isEqualToString:@"昨日"]) {
        titleLabels.text = @"昨日";
    }else if ([model.title isEqualToString:@"上周"]) {
        titleLabels.text = @"上周";
    }else if ([model.title isEqualToString:@"上月"]) {
        titleLabels.text = @"上月";
    }else if ([model.title isEqualToString:@"总计"]) {
        titleLabels.text = @"总计";
    }
}

@end
